import { Component, Vue } from 'vue-property-decorator';

import { getSystemConfig } from '@/service/common-service';

@Component({})
export default class AppLogo extends Vue {

  userName: String = '';
  unitName: String = '';
  logoSrc: String = '';
  logoStyle: any = {};
  titles: Array<any> = [];
  homeUrl: any = '';

  private created() {
    let currentHumanInfo = JSON.parse(sessionStorage.getItem('currentHumanInfo') as string);
    if (currentHumanInfo) {
      this.userName = currentHumanInfo.humanName;
      this.unitName = currentHumanInfo.unitName;
    }
    let sysConfigMap = JSON.parse(sessionStorage.getItem('sysConfigMap') as string);
    if (sysConfigMap) {
      this.logoSrc = sysConfigMap['SYSTEM_LOGO'];
      this.logoStyle = sysConfigMap['SYSTEM_LOGO_STYLE'] ? JSON.parse(sysConfigMap['SYSTEM_LOGO_STYLE']) : {};
      this.titles = sysConfigMap['SYSTEM_HEADER_TITLE'].split('&');
    } else {
      this.getHeaderConfig();
    }
  }
  private activated() {
  }
  private mounted() {
  }

  async getHeaderConfig() {
    this.logoSrc = await getSystemConfig({configKey: 'SYSTEM_LOGO'});
    const logoStyle = await getSystemConfig({configKey: 'SYSTEM_LOGO_STYLE'});
    this.logoStyle = logoStyle ? JSON.parse(logoStyle) : {};
    this.titles = await getSystemConfig({configKey: 'SYSTEM_HEADER_TITLE'});
  }

  toHomepage() {
  }
}